package cn.iocoder.yudao.module.trade.controller.admin.giftcard;

import cn.iocoder.yudao.module.trade.controller.admin.giftcard.vo.CardGroupPageReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.giftcard.vo.CardGroupRespVO;
import cn.iocoder.yudao.module.trade.controller.admin.giftcard.vo.CardGroupSaveReqVO;
import cn.iocoder.yudao.module.trade.dal.dataobject.giftcard.GiftCardGroupDO;
import cn.iocoder.yudao.module.trade.service.giftcard.GiftCardGroupService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;



import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;


@Tag(name = "管理后台 - gift")
@RestController
@RequestMapping("/gift/card-group")
@Validated
public class GiftCardGroupController {

    @Resource
    private GiftCardGroupService cardGroupService;

    @PostMapping("/create")
    @Operation(summary = "创建gift")
    public CommonResult<Long> createCardGroup(@Valid @RequestBody CardGroupSaveReqVO createReqVO) {
        return success(cardGroupService.createCardGroup(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新gift")
    public CommonResult<Boolean> updateCardGroup(@Valid @RequestBody CardGroupSaveReqVO updateReqVO) {
        cardGroupService.updateCardGroup(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除gift")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteCardGroup(@RequestParam("id") Long id) {
        cardGroupService.deleteCardGroup(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得gift")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<CardGroupRespVO> getCardGroup(@RequestParam("id") Long id) {
        GiftCardGroupDO cardGroup = cardGroupService.getCardGroup(id);
        return success(BeanUtils.toBean(cardGroup, CardGroupRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得gift分页")
    public CommonResult<PageResult<CardGroupRespVO>> getCardGroupPage(@Valid CardGroupPageReqVO pageReqVO) {
        PageResult<GiftCardGroupDO> pageResult = cardGroupService.getCardGroupPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, CardGroupRespVO.class));
    }



}
